#include <stdio.h>
#include "mnginx.h"


//发送接收缓冲区
char M_NGINX_RX_BUFF[M_NGINX_RX_BUFF_SIZE] = {0};
char M_NGINX_TX_BUFF[M_NGINX_TX_BUFF_SIZE] = {0};


static int pop_index = 0x00;
static int push_index = 0x00;

void m_pop_clear() {
    pop_index = 0;
}

void m_push_clear() {
    push_index = 0;
}

int m_pop(char *receive_buff, int length) {
    for (; length > 0 && pop_index < M_NGINX_RX_BUFF_SIZE; length--, pop_index++) {
        if (receive_buff != NULL) {
            *receive_buff = M_NGINX_RX_BUFF[pop_index];
            receive_buff++;
        }
    }
    return pop_index;
}

int m_push(char *data_buff, char *data, int length) {
    for (; length > 0 && push_index < M_NGINX_TX_BUFF_SIZE; length--, push_index++) {
        data_buff[push_index] = *data;
        data++;
    }
    return push_index;
}


char *login() {
    return "<h1>this is login</h1>";
}

char *index() {
    return "<h1>this is index</h1>";
}


MNginxRouter m_nginx_router[] = {
        {
                .controller=(void *) login,
                .url="/login",
                .view="/login.html"
        },
        {
                .controller=(void *) index,
                .url="/index",
                .view="/index.html"
        }
};


void m_nginx_parse_request() {
    HttpRequest httpRequest = {0};
    //方法请求方法


    //url

    //http版本

    //标头

    //请求体 如果为post则先获取post参数

    //请求内容

    m_pop(0, 3);
    httpRequest.url = "";
}

void m_nginx_make_response() {

    //填充发送缓冲区

    //调用socket发送数据

}

int main() {
    printf("");
    printf("%s\r\n", ((char *(*)()) (m_nginx_router[0].controller))());
    printf("%s\r\n", ((char *(*)()) (m_nginx_router[1].controller))());

}